
#include <assert.h>
#include "app_platform/cmd_obj.h"
#include "app_platform/cntl_info.h"
#include "app_platform/intf_service_control.h"
#include "gismanageao_adaptor.h"
#include "gismanageao_req_resp.h"


std::string g_sgismanageaoStandAlone;

///////////////////////
// class CGisManageAoSvcFactory
int CGisManageAoSvcFactory::init(void* pvParam)
{
	IUserDefineCntl* pCntl = reinterpret_cast<IUserDefineCntl*>(pvParam);
	assert(pCntl);
    pCntl->getConfig("StandAlone", g_sgismanageaoStandAlone);
         

	return CGisManageAo::Initialize(pCntl);
}

int CGisManageAoSvcFactory::CXYZTimerHandler::OnTimer(int iTimerId)
{
    assert(0);
	return 0;
}

int CGisManageAoSvcFactory::fini(void* pvParam)
{
    return 0;
}

uint32_t CGisManageAoSvcFactory::getCateId() const
{   
	//方法已废弃
    return 0;
}

IService* CGisManageAoSvcFactory::createService(uint32_t dwcmdId)
{
    return (new CGisManageAoService(dwcmdId));
}

void CGisManageAoSvcFactory::getServiceType(ServiceTypeMap_T& mapSvcType)
{
	mapSvcType[GISMANAGEAO_SHIPTYPEAREALOCUSROWSYNC_REQ_CMD_ID] = true;
}

////////////////////////
// class CGisManageAoService
CGisManageAoService::CGisManageAoService(uint32_t dwcmdId) 
: m_dwcmdId(dwcmdId)
{
    enum DeployMethod method = DEPLOY_DETACH;
    if(!g_sgismanageaoStandAlone.empty() && g_sgismanageaoStandAlone != "0") // Stand-Alone
        method = DEPLOY_STANDALONE;
        
    m_pSvc = new CGisManageAo(method);
}

void CGisManageAoService::Reset() 
{ 
	m_pSvc -> Reset();
}
    
void CGisManageAoService::getCmdIdRange(uint32_t& dwcmdIdBegin, uint32_t& dwcmdIdEnd) const 
{ 
    dwcmdIdBegin = m_dwcmdId;
    dwcmdIdEnd = m_dwcmdId;
} 
	
int CGisManageAoService::Execute(CCmdObj& oCmd)
{
	switch(oCmd.getCmdId())
	{
	case GISMANAGEAO_SHIPTYPEAREALOCUSROWSYNC_REQ_CMD_ID:
        return ShipTypeAreaLocusRowSync(oCmd);
	default:
		assert(0);
	}
	return 0;
}

int CGisManageAoService::ShipTypeAreaLocusRowSync(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CGisManageAoShipTypeAreaLocusRowSyncReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	CGisManageAoShipTypeAreaLocusRowSyncResp oResp;
	
    oResp.dwResult = m_pSvc->ShipTypeAreaLocusRowSync(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.shipTypeAreaLocusPo,
		oReq.inReserve,
		oReq.errMsg,
		oReq.outReserve
    );
	oResp.errMsg = oReq.errMsg;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


#include "svc_main.h"

IServiceFactory* GetServiceFactory(void)
{
    return CSvcFactorySingleton::Instance();
}
